package com.ylkj.patient.moduleimpl;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.examination.mlib.constants.ARouterConstants;
import com.examination.mlib.interfaceapi.HomeBackApi;
import com.users.rn.common.cmbroadcast.RNKITTools;
import com.yljk.live.common.utils.MediaCountyManager;
import com.yljk.mcconfig.constants.MCARouter;
import com.ylkj.patient.MainApplication;
import com.ylkj.patient.ui.activities.MainActivity;
import com.ylkj.patient.utils.AppReactUtils;
import com.ylkj.patient.utils.PushMessageUtil;

@Route(path = ARouterConstants.HomeModuleImpl)
public class HomeModuleImpl implements HomeBackApi {

    /**
     * 无参android to rn
     *
     * @param context
     * @param pluginId      rn包名
     * @param componentName rn页面名
     */
    @Override
    public void Android2RnPush(Context context, String pluginId, String componentName) {
        AppReactUtils.INSTANCE.push(context, pluginId, componentName);
    }

    /**
     * 带参androi to rn
     *
     * @param context
     * @param pluginId      rn包名
     * @param componentName rn页面名
     * @param bundle        参数
     */
    @Override
    public void Android2RnPush(Context context, String pluginId, String componentName, Bundle bundle) {
        AppReactUtils.INSTANCE.push(context, pluginId, componentName, bundle);
    }

    @Override
    public View getMainTabLayoutView(Activity activity) {
        if (activity instanceof MainActivity) {
            return ((MainActivity) activity).getMainTabLayoutView();
        }
        return null;
    }

    @Override
    public void homePagePatientPopup(Activity activity) {
        if (activity != null && activity instanceof MainActivity) {
            ((MainActivity) activity).getHomePagePatientPopup(true,true, true, true, false);
        }
    }

    @Override
    public void goHome(Context context) {
        Intent intent = new Intent(context, MainActivity.class);
        MainApplication.homeType = true;
        context.startActivity(intent);
    }

    @Override
    public void toJumeLiveList() {
        ARouter.getInstance().build(MCARouter.HEALTH_LIVE).navigation();
    }

    @Override
    public void toJumeLiveDetail(int id, int client) {
        ARouter.getInstance().build(MCARouter.LIVE_PLAYER)
                .withInt("roomId", id)
                .withInt("liveClient", client)
                .navigation();
    }

    @Override
    public void toBannerClick(String urlString) {
        MediaCountyManager.getInstance().pageClick(urlString);
    }

    @Override
    public void toScheme(Context context,String h5Url) {
        PushMessageUtil.getInstance().dealMessage(context,h5Url);
    }

    @Override
    public void sendBrocast(Context context, String pageName, String params) {
        RNKITTools.INSTANCE.sendBroadcast(context,pageName,params);
    }

    @Override
    public void init(Context context) {

    }

    @Override
    public void hideImLayout(Activity activity) {
        if (activity != null && activity instanceof MainActivity){
            ((MainActivity)activity).hideImLayout();
        }
    }

    @Override
    public void showImLayout(Activity activity) {
        if (activity != null && activity instanceof MainActivity){
            ((MainActivity)activity).showImLayout();
        }
    }


}
